package com.exam.Mapper;

import com.exam.Entity.Score;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ScoreMapper {
    /**
     * @param score 添加一条成绩记录
     * @return
     */
    @Options(useGeneratedKeys = true,keyProperty = "scoreId")
    @Insert("insert into score(sno,subject,paperId) values(#{sno},#{subject},#{paperId})")
    int add(Score score);

    @Select("select scores,sno,subject,paperId,answerDate from score order by scoreId desc")
    List<Score> findAll();

    // 分页
    @Select("select scoreId,scores,sno,subject,paperId,answerDate from score where sno = #{sno} order by scoreId desc")
    List<Score> findById(Integer sno);

    // 不分页
//    @Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score where studentId = #{studentId}")
//    List<Score> findById(Integer studentId);

    /**
     *
     * @return 查询每位学生的学科分数。 max其实是假的，为了迷惑老师，达到一次考试考生只参加了一次的效果
     */
    @Select("select scores from score as s join exam_manage as e on s.paperId = e.paperId where examId = #{examId} group by sno")
    List<Score> findByExamCode(Integer examId);
}
